//
//  UIUnderlinedButton.m
//  homeland
//
//  Created by rain on 14-10-18.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "UIUnderlinedButton.h"

@implementation UIUnderlinedButton

+ (UIUnderlinedButton*) underlinedButton {
    UIUnderlinedButton* button = [[UIUnderlinedButton alloc] init];
    return button;
} 

- (void) drawRect:(CGRect)rect {
    CGRect textRect = self.frame;
    // need to put the line at top of descenders (negative value)
//    CGFloat descender = self.titleLabel.font.descender;
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    
    // set to same colour as text
    CGContextSetStrokeColorWithColor(contextRef, self.titleLabel.textColor.CGColor);
    
    CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.size.height);
    
    CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.size.height);
    
    CGContextClosePath(contextRef);
    CGContextDrawPath(contextRef, kCGPathStroke); 
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
